package com.artifact.api.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.artifact.api.sdk.WXPay;
import com.artifact.api.sdk.WXPayConfig;

@Configuration
public class WXPayBeanConfig {

	@Value("${wx.app.appId}")  
	private String appId;
	@Value("${wx.app.mchid}")  
	private String mchid;
	@Value("${wx.app.key}")  
	private String key;
	
	@Bean(name = "appConfig")
	public WXPayConfig wxPayConfig(@Value("${wx.app.key}") String key,
            @Value("${wx.app.appId}") String appId, @Value("${wx.app.mchid}") String mchId) throws Exception{
		WXPayConfig appWXPayConfig = new WXPayConfig();
		appWXPayConfig.setAppId(appId);
		appWXPayConfig.setMchid(mchId);
		appWXPayConfig.setKey(key);
		return appWXPayConfig;
	}
	
	@Bean(name = "appPay")
	public WXPay wxPay(@Autowired WXPayConfig appConfig) throws Exception{
		WXPay appWXPay = new WXPay(appConfig);
		return appWXPay;
	}


	/**
	 * 注册阿里支付bean
	 * @param serverUrl
	 * @param appId
	 * @param privateKey
	 * @return
	 * @throws Exception
	 */
	/**
	@Bean(name = "clientBuilder")
	public ClientBuilder clientBuilder(@Value("${ali.app.serverUrl}") String serverUrl,
            @Value("${ali.app.appId}") String appId, @Value("${ali.app.privateKey}") String privateKey
            ,@Value("${ali.app.publicKey}") String publicKey
            ) throws Exception{
		ClientBuilder clientBuilder = new ClientBuilder();
		clientBuilder.setAlipayPublicKey(publicKey);
		clientBuilder.setAppid(appId);
		clientBuilder.setCharset("utf-8");
		clientBuilder.setFormat("json");
		clientBuilder.setGatewayUrl(serverUrl);
		clientBuilder.setPrivateKey(privateKey);
		clientBuilder.setSignType("RSA2");
		return clientBuilder;
	}
	
	@Bean(name = "aliPay")
	public AlipayTradeServiceImpl alipayTradeService(@Autowired ClientBuilder clientBuilder) throws Exception{
		AlipayTradeServiceImpl alipayTradeServiceImpl = new AlipayTradeServiceImpl(clientBuilder);
		return alipayTradeServiceImpl;
	}*/

}
